﻿
    using Chain.BLL;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public partial class ShopPointTransfer : PageBase
    {


        protected void btnShopPointQuery_Click(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.GetShopPointList(this.QueryCondition());
        }

        protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.NetPagerParameter.PageSize = int.Parse(this.drpPageSize.SelectedValue);
            this.GetShopPointList(this.QueryCondition());
        }

        private void GetShopPointList(string strSql)
        {
            SysShopPointLog bllShopPointLog = new SysShopPointLog();
            int Counts = this.NetPagerParameter.RecordCount;
            strSql = PubFunction.GetShopAuthority(base._UserShopID, "SysShopPointLog.OutShopID", strSql);
            DataTable dtShopPoint = bllShopPointLog.GetListSP(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts, new string[] { strSql }).Tables[0];
            this.NetPagerParameter.RecordCount = Counts;
            this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[] { this.NetPagerParameter.CurrentPageIndex, this.NetPagerParameter.PageCount, this.NetPagerParameter.RecordCount, this.NetPagerParameter.PageSize });
            this.gvShopPointList.DataSource = dtShopPoint;
            this.gvShopPointList.DataBind();
            PageBase.BindSerialRepeater(this.gvShopPointList, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
        }

        protected void gvShopPointList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                DataRowView dr = (DataRowView) e.Item.DataItem;
                Label lblShopPointype = e.Item.FindControl("lblShopPointType") as Label;
                switch (Convert.ToInt32(dr["ShopPointType"]))
                {
                    case 0:
                        lblShopPointype.Text = "总店增加";
                        return;

                    case 1:
                        lblShopPointype.Text = "总店扣除";
                        return;

                    case 2:
                        lblShopPointype.Text = "消费扣除";
                        return;

                    case 3:
                        lblShopPointype.Text = "兑换增加";
                        return;

                    default:
                        return;
                }
            }
        }

        protected void NetPagerParameter_PageChanging(object src, PageChangingEventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = e.NewPageIndex;
            this.GetShopPointList(this.QueryCondition());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                PubFunction.BindShopSelect(base._UserShopID, this.sltShop, true);
                this.sltShop.Items.Remove(new ListItem("深圳-总部", "1"));
                this.GetShopPointList(this.QueryCondition());
            }
        }

        protected string QueryCondition()
        {
            string strMemShopID = this.sltShop.Value;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SysShopPointLog.UserID = SysUser.UserID AND SysShopPointLog.OutShopID = SysShop.ShopID ");
            if (strMemShopID != "")
            {
                strSql.AppendFormat(" and OutShopID={0}", int.Parse(strMemShopID));
            }
            if (this.sltCzlx.Value != "")
            {
                strSql.AppendFormat(" and ShopPointType = '{0}'", this.sltCzlx.Value);
            }
            if (this.txtShopPointAccount.Value.Trim() != "")
            {
                strSql.AppendFormat(" and ShopPointAccount='{0}'", this.txtShopPointAccount.Value.Trim());
            }
            return strSql.ToString();
        }
    }


